package gameManager;

import java.awt.Point;
import java.util.List;

public abstract class WeaponObject {

    private Point myPosition;
    private int cooldownTime;
    private int myWeaponLevel;
    private String myWeaponName;
    private int timeUntilNextFire;
    private int triggerTimeFromLastFired;
    private AmmunitionObject myAmmunition;
    private GameCharacter myParent;
    
    
    public WeaponObject (int weaponLevel, int cooldownTime, GameCharacter parent) {
        setWeaponLevel(weaponLevel);
        setCooldownTime(cooldownTime);  
        triggerTimeFromLastFired = 0;
        myPosition = new Point(parent.getCenter().x, parent.getCenter().y);
        myParent = parent;
        //myPosition.move(parent.getCenter().x + Math.round(parent.getDimension().width/2), parent.getCenter().y);
    }

    public void setWeaponName (String newWeaponName) {
        myWeaponName = newWeaponName;
    }
    
    public String getWeaponName() {
        return myWeaponName;
    }
    public int getWeaponLevel() {
        return myWeaponLevel;
    }
    public void setWeaponLevel(int newWeaponLevel) {
        myWeaponLevel = newWeaponLevel;
    }

    public void changeWeaponLevel (int dWeaponLevel) {
        myWeaponLevel += dWeaponLevel;
    }

    public int getCooldownTime() {
        return cooldownTime;
    }

    public void setCooldownTime(int newCoolDownTime) {
        cooldownTime = newCoolDownTime;
    }

    public void changeCoolDownTime(int dCoolDownTime) {
        cooldownTime += dCoolDownTime;
    }
    
    public void updateCoolDownWaitingTime(int trigger) {

        timeUntilNextFire = cooldownTime + triggerTimeFromLastFired - trigger;
        if (timeUntilNextFire < 0) {
            timeUntilNextFire = 0;
        }
        triggerTimeFromLastFired = trigger;
    }
    
    public AmmunitionObject getWeaponAmmunition() {
        return myAmmunition;
    }
    
    public void setWeaponAmmunition(AmmunitionObject newAmmo) {
        myAmmunition = newAmmo;
    }

    public abstract List<AmmunitionObject> fire();
    
    public boolean okayToFire(){
        return (timeUntilNextFire <= 0);
    }
    
    public Point getPosition(){
        return myPosition;
    }
    
    public void setPosition(Point newPosition){
        myPosition = newPosition;
    }
    
    public GameCharacter getParent(){
        return myParent;
    }
}
